//
// Copyright (c) 2009 All Right Reserved
//
// vl
//
// 2009-01-01
// Contains ...
namespace LargoCommon.Music
{
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.IO;
using System.Xml.Linq;
using Support;
///
/// Data Analysis.
///
public class DataAnalysis
{
///
/// Singleton variable.
///
private static readonly DataAnalysis InternalSingleton = new DataAnalysis();
#region Constructors
///
/// Prevents a default instance of the DataAnalysis class from being created.
///
private DataAnalysis() {
}
#endregion
#region Static properties
///
/// Gets the ProcessLogger Singleton.
///
/// Property description.
public static DataAnalysis Singleton {
get {
Contract.Ensures(Contract.Result() != null);
if (InternalSingleton == null) {
throw new InvalidOperationException("Singleton DataAnalysis is null.");
}
return InternalSingleton;
}
}
#endregion
#region List Properties
///
/// Gets or sets the orchestra blocks list.
///
///
/// The orchestra blocks list.
///
public List OrchestraBlockList { get; set; }
#endregion
#region Public methods OrchestraBlocks
///
/// Loads the blocks.
///
public void LoadOrchestraBlocks() {
this.OrchestraBlockList = new List();
var path = MusicalSettings.Singleton.Folders.GetFolder(MusicalFolder.UserData);
var fileName = "OrchestraBlocks.xml";
var filepath = Path.Combine(path, fileName);
if (!File.Exists(filepath)) {
return;
}
var xdoc = XDocument.Load(filepath);
var root = xdoc.Root;
if (root == null || root.Name != "OrchestraBlocks") {
return;
}
var xlist = root;
foreach (var xblock in xlist.Elements()) {
OrchestraBlock block = new OrchestraBlock(xblock);
if (block.Strip.OrchestraTracks.Count > 0) {
this.OrchestraBlockList.Add(block);
}
}
}
///
/// Saves the blocks.
///
[JetBrains.Annotations.UsedImplicitlyAttribute]
public void SaveOrchestraBlocks() {
XElement xlist = new XElement("OrchestraBlocks");
foreach (var block in this.OrchestraBlockList) {
if (block.Strip.OrchestraTracks.Count == 0) {
continue;
}
var xblock = block.GetXElement;
xlist.Add(xblock);
}
var xdoc = new XDocument(new XDeclaration("1.0", "utf-8", null), xlist);
var path = MusicalSettings.Singleton.Folders.GetFolder(MusicalFolder.UserData);
var fileName = "OrchestraBlocks.xml";
var filepath = Path.Combine(path, fileName);
xdoc.Save(filepath);
}
#endregion
}
}